#include "CLog.h"

namespace cfe
{

IMPLEMENT_SINGLETON(CLog)

CLog* CLog::getLogInstance()
{
	if(!s_pSingleton)
		s_pSingleton = new CLog;
	return s_pSingleton;
}
//-----------------------------------------------------------------------------
// Name: XLogError(char *lpszText, ...)
// Desc: Logging
//-----------------------------------------------------------------------------
void CLog::LogError(char* lpszText, ...)
{
  if(m_bEnable)
  {
    va_list argList;

    //Initialize variable argument list
    va_start(argList, lpszText);

    //Write the error to the log file
    fprintf(m_logFile, "<font face=\"Arial\" size=\"2\" color=\"#FF0000\"><b>");
    vfprintf(m_logFile, lpszText, argList);
    fprintf(m_logFile, "</b></font><br>\n");

    va_end(argList);
  }
}
//-----------------------------------------------------------------------------
// Name: XWriteToLog(char *lpszText, ...)
// Desc: Logging
//-----------------------------------------------------------------------------
void CLog::WriteToLog(char* lpszText, ...)
{
  if(m_bEnable)
  {
    va_list argList;

    //Initialize variable argument list
    va_start(argList, lpszText);

    //Write the error to the log file
    fprintf(m_logFile, "<font face=\"Arial\" size=\"2\" color=\"#000000\">");
    vfprintf(m_logFile, lpszText, argList);
    fprintf(m_logFile, "</font><br>\n");

    va_end(argList);
  }
}
//-----------------------------------------------------------------------------
// Name: XLogWarning(char *lpszText, ...)
// Desc: Logging
//-----------------------------------------------------------------------------
void CLog::LogWarning(char* lpszText, ...)
{
  if(m_bEnable)
  {
    va_list argList;

    //Initialize variable argument list
    va_start(argList, lpszText);

    //Write the error to the log file
    fprintf(m_logFile, "<font face=\"Arial\" size=\"2\" color=\"#E7651A\"><b>");
    vfprintf(m_logFile, lpszText, argList);
    fprintf(m_logFile, "</b></font><br>\n");

    va_end(argList);
  }
}
//-----------------------------------------------------------------------------
// Name: XBeginLogging()
// Desc: Logging
//-----------------------------------------------------------------------------
void CLog::BeginLogging( const char* logFile )
{
  if( !m_bEnable )
  {
    m_logFile = fopen( logFile, "wb" );
    if(m_logFile != NULL)
    {
      m_bEnable = true;

      fprintf(m_logFile, "<html><head><title>Log File</title></head><body>\n");
      fprintf(m_logFile, "<font face=\"Arial\" size=\"4\" color=\"#000000\"><b><u>Log File</u></b></font><br>\n");
    }
    else
    {
      m_bEnable = true;
    }
  }
}
//-----------------------------------------------------------------------------
// Name: XEndLogging()
// Desc: Logging
//-----------------------------------------------------------------------------
void CLog::EndLogging()
{
  if(m_bEnable)
  {
    fprintf(m_logFile, "</body></html>");
    fclose(m_logFile);
    m_bEnable = false;
  }
}


};//end cfe